﻿

namespace FileStrider
{
    using System.Windows.Controls;

    using System.IO;
    /// <summary>
    /// Interaction logic for ListItemFolder.xaml
    /// </summary>
    public partial class ListItemFolder : UserControl
    {
        public DirectoryInfo FolderInfo;

        public ListItemFolder(string folder, long size)
        {
            InitializeComponent();

            var directoryInfo       = new DirectoryInfo(folder);
            FolderInfo              = directoryInfo;
            LabelFolderName.Content = directoryInfo.FullName;
            LabelSIze.Content       = size.ToString("N0") + " Mb";

            // Get folder attributes for coloring
            if ((directoryInfo.Attributes & FileAttributes.Hidden)     != 0) { LabelFolderName.Foreground = Helper.HiddenFileColor; }
            if ((directoryInfo.Attributes & FileAttributes.Encrypted)  != 0) { LabelFolderName.Foreground = Helper.EncryptedFileColor; }
            if ((directoryInfo.Attributes & FileAttributes.Compressed) != 0) { LabelFolderName.Foreground = Helper.CompressedFileColor; } 

            try
            {
                ImageIcon.Source = Helper.GetDriveIcon(directoryInfo.FullName);
            }
            catch (Helper.IconReadException)
            {
                // Sometimes unable to retrive folder icon, just skip it
            }
            
        }
    }
}
